import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {path: '/:pathMatch(.*)', redirect: '/404'},  //所有错误路由都重定向到/404页面
        {
            path: '/',
            redirect: '/manager/home'
        },
        {
            path: '/404',
            name: 'NotFund',
            meta: {
                title: '404页面不存在'
            },
            component: () => import('../views/404.vue')
        },
        {
            path: '/manager',
            children: [
                {
                    path: 'home',
                    name: 'home',
                    meta: {
                        title: '首页'
                    },
                    component: () => import('../views/Home.vue')
                },
                {
                    path: 'longin',
                    name: 'longin',
                    meta: {
                        title: '登录'
                    },
                    component: () => import('../views/Longin.vue')
                },
                {
                    path: 'data',
                    name: 'data',
                    meta: {
                        title: '数据详情'
                    },
                    component: () => import('../views/Data.vue')
                },
            ],
            name: 'manager',
            component: () => import('../views/Manager.vue')
        },

    ],
})

//路由守卫
router.beforeEach((to, from, next) => {
    document.title = to.meta.title
    next()
})

export default router
